package GUI.Usuario;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JScrollPane;

import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;

import BBDD.ManageAlumno;
import DAO.AlumnoDAO;
import Logica.CodeFrameAlumno;
import Logica.CodeFramePrincipal;
import Modelos.AlumnoTableModel;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Vector;

public class Alumnos extends JFrame {

	private JPanel contentPane;
	private final JPanel panel = new JPanel();
	private int codprofesor;
	private JTable table;
	private int id_modulo;
	private int id_grupo;
	private String nom_modulo;
	private JLabel lblNomModulo = new JLabel(nom_modulo);

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Alumnos frame = new Alumnos();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Alumnos() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 589, 492);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnArchivo = new JMenu("Archivo");
		menuBar.add(mnArchivo);

		JMenu mnEditar = new JMenu("Editar");
		menuBar.add(mnEditar);

		JMenu mnAdministrar = new JMenu("Administrar");
		menuBar.add(mnAdministrar);

		JMenu mnAyuda = new JMenu("Ayuda");
		menuBar.add(mnAyuda);

		JMenu mnAcercaDe = new JMenu("Acerca de");
		menuBar.add(mnAcercaDe);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		// Boton solo visible con rol administrador.
		JButton btnNota = new JButton(" A\u00F1adir Nota");
		btnNota.setIcon(new ImageIcon(Alumnos.class
				.getResource("/Utilidades/notas.png")));
		btnNota.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Notas notas = new Notas();
				notas.setVisible(true);
			}
		});

		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.setIcon(new ImageIcon(Alumnos.class
				.getResource("/Utilidades/cancelar.png")));
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});

		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(gl_contentPane
				.createParallelGroup(Alignment.TRAILING)
				.addComponent(panel, GroupLayout.DEFAULT_SIZE, 563,
						Short.MAX_VALUE)
				.addGroup(
						gl_contentPane
								.createSequentialGroup()
								.addContainerGap(288, Short.MAX_VALUE)
								.addComponent(btnNota)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(btnCancelar,
										GroupLayout.PREFERRED_SIZE, 126,
										GroupLayout.PREFERRED_SIZE)
								.addContainerGap()));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addComponent(panel, GroupLayout.PREFERRED_SIZE, 355,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(
								gl_contentPane
										.createParallelGroup(Alignment.LEADING)
										.addComponent(btnCancelar,
												GroupLayout.DEFAULT_SIZE, 51,
												Short.MAX_VALUE)
										.addComponent(btnNota,
												GroupLayout.DEFAULT_SIZE, 51,
												Short.MAX_VALUE))
						.addContainerGap()));

		lblNomModulo.setFont(new Font("Tahoma", Font.PLAIN, 18));

		JScrollPane scrollPane = new JScrollPane();
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(gl_panel
				.createParallelGroup(Alignment.LEADING)
				.addGroup(
						gl_panel.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										gl_panel.createParallelGroup(
												Alignment.LEADING)
												.addGroup(
														gl_panel.createSequentialGroup()
																.addComponent(
																		scrollPane,
																		GroupLayout.DEFAULT_SIZE,
																		543,
																		Short.MAX_VALUE)
																.addContainerGap())
												.addComponent(lblNomModulo))));
		gl_panel.setVerticalGroup(gl_panel.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_panel.createSequentialGroup()
						.addContainerGap()
						.addComponent(lblNomModulo)
						.addGap(18)
						.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE,
								293, Short.MAX_VALUE).addContainerGap()));

		table = new JTable();
		table.setModel(new DefaultTableModel(new Object[][] { { null }, },
				new String[] { "New column" }));
		scrollPane.setViewportView(table);
		panel.setLayout(gl_panel);
		contentPane.setLayout(gl_contentPane);

	}

	public String sacaIDAlumno() {
		int fila = table.getSelectedRow();
		String id = (String) table.getValueAt(fila, 0);
		return id;
	}

	public void setcodProfesor(int codprofesor) {
		this.codprofesor = codprofesor;

	}

	public void setNomModulo(String nom_modulo) {
		this.nom_modulo = nom_modulo;
		lblNomModulo.setText("Alumnos de: " + nom_modulo);
		CodeFrameAlumno logicObject = new CodeFrameAlumno();
		logicObject.setCodProfesor(codprofesor);
		logicObject.setIDModulo(id_modulo);
		logicObject.setIDGrupo(id_grupo);
		logicObject.fillTableAlumnos();
		table.setModel(logicObject.getTableModel());
	}

	public void setidModulo(int id_modulo) {
		this.id_modulo = id_modulo;
	}

	public void setIDGrupo(int id_grupo) {
		this.id_grupo = id_grupo;
	}
}
